<template>
  <el-dialog :title="dialogTit" :visible.sync="projectcertVisible" :close-on-click-modal="false"
             :append-to-body="true" :modal-append-to-body="false">
    <div class="mod-prod-info">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
        <el-form-item label="许可证号" prop="certificateno">
          <el-input v-model="dataForm.certificateno" placeholder="许可证号"></el-input>
        </el-form-item>
        <el-form-item label="绑定楼号" prop="bindbuildingno">
          <el-input v-model="dataForm.bindbuildingno" placeholder="绑定楼号"></el-input>
        </el-form-item>
        <el-form-item label="发证日期" prop="issuedate">
          <el-input v-model="dataForm.issuedate" placeholder="发证日期"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"
                     @click="dataFormSubmit()">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>

</template>
<script>
import { getUUID } from '@/utils'
import {Debounce} from "@/utils/debounce";
export default {
  name:'projectcert',
  data(){
    return {
      dialogTit: '维护许可证信息',
      projectcertVisible : false,
      dataForm: {
        id: '',
        pid: '',
        certificateno: '',
        bindbuildingno: '',
        issuedate: ''
      },
      dataRule: {
        certificateno: [
          { required: true, message: '名称不能为空', trigger: 'blur' },
          { pattern: /\s\S+|S+\s|\S/, message: '请输入正确的许可证名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods : {
    init(pid){
      this.projectcertVisible = true
      this.dataForm.pid = pid
      console.info("父组件传过来的PID")
      console.info(this.dataForm.pid)
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
      })
    },
    dataFormSubmit: Debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/project/saveProjectPresalecart`),
            method: 'post',
            data: this.$http.adornData({
              'id': Date.now(),
              'pid': this.dataForm.pid,
              'certificateno': this.dataForm.certificateno,
              'bindbuildingno': this.dataForm.bindbuildingno,
              'issuedate': this.dataForm.issuedate
            })
          }).then(({data}) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.projectcertVisible = false
                this.$emit('refreshCert')
              }
            })
          })
        }
      })
    })
  }

}
</script>
